<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Config extends Model {
    protected $fillable = ['key', 'value', 'title'];

    public $timestamps = false;
    CONST SMS_SIGN = '[]';

    const SEX_MALE = 1;
    const SEX_FEMAL = 2;

    const MAX_DAYS = 20;

    public static $sexMaps = [
        self::SEX_MALE => '男',
        self::SEX_FEMAL => '女'
    ];

    const RESULT_FORM_SUCCESS = 1;
    const RESULT_FORM_FAIL = 2;
    public static $resultFormOptions = [self::RESULT_FORM_SUCCESS => '通过', self::RESULT_FORM_FAIL => '未通过'];

    public static $relationTableMaps = [
        'dy_base_infos' => '全体党员名册',
        'dy_qcs' => '迁出党员名册',
        'dy_qrs' => '迁入党员名册',
        'dy_xfzdys' => '新发展党员名册',
        'dy_fzdxs' => '发展对象名册',
        'dy_jjfzs' => '入党积极分子名册',
        'dzz_yjdzz_infos' => '院级党组织所属党总支名册',
        'dzz_infos' => '党支部名册',
        'ddb_first' => \App\Models\DdbFirst::NAME,
        'ddb_lw' => \App\Models\DdbLw::NAME,
        'ddb_second' => \App\Models\DdbSecond::NAME,
        'dy_hfdjs' => DyHfdj::NAME,
        'dy_tzdjs' => DyTzdj::NAME,
        'dy_cgjs' => DyCgj::NAME,
        'dy_ld' => DyLd::NAME,
        'ddb_users' => DdbUser::NAME,
        'ddb_cbrx' => DdbCbrx::NAME,
        'ddb_ybrx' => DdbYbrx::NAME,
    ];

    public static $relationClassMaps = [
        'dy_base_infos' => \App\Models\DyBaseInfo::class,
        'dy_qcs' => \App\Models\DyQc::class,
        'dy_qrs' => \App\Models\DyQr::class,
        'dy_xfzdys' => \App\Models\DyXfzdy::class,
        'dy_fzdxs' => \App\Models\DyFzdx::class,
        'dy_jjfzs' => \App\Models\DyJjfz::class,
        'dzz_yjdzz_infos' => \App\Models\DzzYjdzzInfo::class,
        'dzz_infos' => \App\Models\DzzInfo::class,
        'ddb_first' => \App\Models\DdbFirst::class,
        'ddb_lw' => \App\Models\DdbLw::class,
        'ddb_second' => \App\Models\DdbSecond::class,
        'dy_hfdjs' => DyHfdj::class,
        'dy_tzdjs' => DyTzdj::class,
        'dy_cgjs' => DyCgj::class,
        'dy_ld' => DyLd::class,
        'ddb_users' => DdbUser::class,
        'ddb_cbrx' => DdbCbrx::class,
        'ddb_ybrx' => DdbYbrx::class,
    ];

    public static function getLinks() {
        return [
            ['title' => '表1 全体党员名册', 'url' => admin_route('base_infos.index'), 'table' => 'dy_base_infos', 'trans' => 'dy-base-info', 'second_title' => '（截止到2023.12.31）'],
            ['title' => '表2 迁出党员名册', 'url' => admin_route('qcs.index'), 'table' => 'dy_qcs', 'trans' => 'dy-qc'],
            ['title' => '表3 迁入党员名册', 'url' => admin_route('qrs.index'), 'table' => 'dy_qrs', 'trans' => 'dy-qr'],
            ['title' => '表4 新发展党员名册', 'url' => admin_route('xfzdys.index'), 'table' => 'dy_xfzdys', 'trans' => 'dy-xfzdy'],
            ['title' => '表5 发展对象名册', 'url' => admin_route('fzdxs.index'), 'table' => 'dy_fzdxs', 'trans' => 'dy-fzdx'],
            ['title' => '表6 入党积极分子名册', 'url' => admin_route('jjfzs.index'), 'table' => 'dy_jjfzs', 'trans' => 'dy-jjfz', 'second_title' => '（已是发展对象的不重复统计）'],
            ['title' => '表7 院级党组织所属党总支名册', 'url' => admin_route('yjdzzs.index'), 'table' => 'dzz_yjdzz_infos', 'trans' => 'dzz-yjdzz-info'],
            ['title' => '表8 党支部名册', 'url' => admin_route('dzz_infos.index'), 'table' => 'dzz_infos', 'trans' => 'dzz-info'],
            ['title' => '表9 恢复党籍人员名册', 'url' => admin_route('hfdj.index'), 'table' => 'dy_hfdjs', 'trans' => 'dy-hfdj'],
            ['title' => '表10 停止党籍人员名册', 'url' => admin_route('tzdj.index'), 'table' => 'dy_tzdjs', 'trans' => 'dy-tzdj'],
            ['title' => '表11 出国（境）党员名册', 'url' => admin_route('cgj.index'), 'table' => 'dy_cgjs', 'trans' => 'dy-cgj'],
            ['title' => '表12 流动党员统计', 'url' => admin_route('ld.index'), 'table' => 'dy_ld', 'trans' => 'dy-ld'],
        ];
    } 

    public static function getLinksForDDb() {
        return [
            '党代表' => [
                ['title' => '模板02 推荐人选名单',  'title_html' => '模板02 推荐人选名单<br/>（1:1.3）', 'url' => admin_route('ddb_first.index'), 'table' => 'ddb_first', 'trans' => 'dy-first'],
                ['title' => '模板03 初步人选名单',  'title_html' => '模板03 初步人选名单<br/>（1:1.2）', 'url' => admin_route('ddb_cbrx.index'), 'table' => 'ddb_cbrx', 'trans' => 'ddb-cbrx'],
                ['title' => '模板10 预备人选登记表',  'title_html' => '模板10 预备人选登记表', 'url' => admin_route('ddb_user.index'), 'table' => 'ddb_users', 'trans' => 'ddb-user'],
                ['title' => '模板09 初步人选名单',  'title_html' => '模板09 预备人选名单<br/>（1:1.2）', 'url' => admin_route('ddb_ybrx.index'), 'table' => 'ddb_ybrx', 'trans' => 'ddb-ybrx'],
            ],
            '两委委员' => [
                ['title' => '模板02 候选人推荐人选名单',  'title_html' => '模板02 候选人推荐人选名单', 'url' => admin_route('ddb_lw.index'), 'table' => 'ddb_lw', 'trans' => 'dy-lw'],
            ]
        ];
    } 

    public static $idTypeMaps = [
        '1' => '身份证',
        '2' => '护照',
        '5' => '港澳居民来往内地通行证',
        '6' => '台湾居民来往大陆通行证'
    ];

    public static $idTypeMapsForSelect = [
        ['title' => '身份证', 'value' => 1],
        ['title' => '护照', 'value' => 2],
        ['title' => '港澳居民来往内地通行证', 'value' => 5],
        ['title' => '台湾居民来往大陆通行证', 'value' => 6],
    ];

    public static function getTextForConstField($field, $value)
    {
        if ($field == 'sex') {
            return isset(self::$sexMaps[$value]) ? self::$sexMaps[$value] : '';
        } else {
            return $value;
        }
    }
}
